<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>视差滚动</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    section {
      width: 100%;
      height: 100vh;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  </style>
</head>

<body>
  <section>
    <h1>美女1</h1>
  </section>
  <section>
    <h1>美女2</h1>
  </section>
  <section>
    <h1>美女3</h1>
  </section>
  <section>
    <h1>美女4</h1>
  </section>
  <section>
    <h1>美女5</h1>
  </section>
  <script src="https://cdn.bootcdn.net/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script>
  <script>
    const sections = document.querySelectorAll('section');
    sections.forEach((section, index) => {
      section.style.background = `url(./assets/${index + 1}.jpg)`;
      section.style.backgroundSize = 'cover';
      section.style.backgroundPosition = 'center';
      section.style.backgroundRepeat = 'no-repeat';
      gsap.fromTo(section, {
        backgroundPositionY: `-${window.innerHeight / 2}px`
      }, {
        backgroundPositionY: `${window.innerHeight / 2}px`,
        ease: 'none',
        scrollTrigger: {
          trigger: section,
          scrub: true
        }
      })
    });
  </script>
</body>

</html>